import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '主页',
      component: () => import('@/views/dashboard/index'),
      meta: {
        title: '主页',
        icon: 'dashboard'
      }
    }]
  },  {
    path: '/system',
    component: Layout,
    meta: {
      title: '系统管理',
      icon: 'el-icon-s-tools'
    },
    children: [{
      path: '/user',
      component: () => import('@/views/system/user'),
      name: '员工管理',
      meta: {
        title: '员工管理'
      }
    }, {
      path: '/role',
      component: () => import('@/views/system/role'),
      name: '角色管理',
      meta: {
        title: '角色管理'
      }
    }, {
      path: '/module',
      component: () => import('@/views/system/module'),
      name: '模块管理',
      meta: {
        title: '模块管理'
      }
    }]
  },
  {
    path: '/stock',
    component: Layout,
    meta: {
      title: '库存管理',
      icon: 'el-icon-box'
    },
    children: [{
        path: '/depot',
        component: () => import('@/views/stock/depot'),
        name: '仓库管理',
        meta: {
          title: '仓库管理'
        }
      }, {
        path: '/purchase',
        component: () => import('@/views/stock/purchase'),
        name: '进货申请',
        meta: {
          title: '进货申请'
        }
      }, {
        path: '/purchaseLog',
        component: () => import('@/views/stock/purchaseLog'),
        name: '进货申请管理',
        meta: {
          title: '进货申请管理'
        }
      },{
        path: '/refund',
        name: '退货申请',
        component: () =>
          import('@/views/stock/refund'),
        meta: {
          title: '退货申请',
          icon: 'tree'
        }
      }, {
        path: 'losses',
        name: 'losses',
        component: () =>
          import('@/views/stock/losses/index'),
        meta: {
          title: '报损日志',
          icon: 'table'
        }
      }, {
        path: 'Inventory',
        name: 'Inventory',
        component: () =>
          import('@/views/stock/Inventory/index'),
        meta: {
          title: '库存',
          icon: 'el-icon-minus'
        }
      }, {
        path: 'lossesadd',
        name: 'lossesadd',
        component: () =>
          import('@/views/stock/losses/add'),
        meta: {
          title: '商品报损',
          icon: 'el-icon-minus'
        }
      },
      {
        path: 'overflow',
        name: 'overflow',
        component: () =>
          import('@/views/stock/overflow/index'),
        meta: {
          title: '报溢日志',
          icon: 'tree'
        }
      },
      {
        path: 'overflowadd',
        name: 'overflowadd',
        component: () =>
          import('@/views/stock/overflow/add'),
        meta: {
          title: '商品报溢',
          icon: 'el-icon-plus'
        }
      }
    ]
  },


  {
    path: '/shangpin',
    component: Layout,
    meta: {
      title: '基本信息',
      icon: 'el-icon-s-order'
    },
    children: [{
        path: '/product',
        component: () => import('@/views/shangpin/product/show.vue'),
        name: '商品信息',
        meta: {
          title: '商品信息'
        }
      },
      {
        path: '/producttype',
        component: () => import('@/views/shangpin/producttype/index.vue'),
        name: '商品类别',
        meta: {
          title: '商品类别'
        }
      },
      {
        path: '/supplier',
        component: () => import('@/views/shangpin/supplier/index.vue'),
        name: '供应商信息',
        meta: {
          title: '供应商信息'
        }
      },
    ]
  },
  {
    path: '/sale',
    component: Layout,
    meta: {
      title: '销售管理',
      icon: 'el-icon-s-shop'
    },
    children: [{
        path: '/customer',
        component: () => import('@/views/sale/customer'),
        name: '客户管理',
        meta: {
          title: '客户管理'
        }
      },
      {
        path: '/sale',
        component: () => import('@/views/sale/sale'),
        name: '销售申请',
        meta: {
          title: '销售申请'
        }
      },
      {
        path: '/saleList',
        component: () => import('@/views/sale/saleList'),
        name: '销售申请管理',
        meta: {
          title: '销售申请管理'
        }
      }
    ]
  },
{
    path: '/mixins',
    component: Layout,
    meta: {
      title: '统计管理',
      icon: 'el-icon-s-shop'
    },
    children: [{
        path: '/saleCount',
        component: () => import('@/views/mixins/salemixins'),
        meta: {
          title: '销售统计'
        }
     },{
        path: '/purCount',
        component: () => import('@/views/mixins/purmixins'),
        meta: {
          title: '采购统计'
        }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
